package design.structure_adapter;

import org.junit.Test;

/**
 * 对象适配器模式
 */
public class DemoObjectAdapter {
    @Test
    public void test(){
        V220Power v220Power = new V220Power();
        V5PowerAdapter adapter = new V5PowerAdapter(v220Power);
        new Mobile().inputPower(adapter);
    }

    public interface V5Power{
        int provideV5Power();
    }

    public class V220Power {
        public int provideV220Power() {
            return 220;
        }
    }

    public class V5PowerAdapter implements V5Power{
        private V220Power v220Power ;
        public V5PowerAdapter(V220Power v220Power){
            this.v220Power = v220Power ;
        }

        @Override
        public int provideV5Power(){
            return v220Power.provideV220Power() - 215;
        }
    }

    public class Mobile {
        public void inputPower(V5Power power) {
            int provideV5Power = power.provideV5Power();
            if (provideV5Power > 5) {
                throw new RuntimeException("电压过大");
            }else{
                System.out.println("手机正常充电");
            }
        }
    }
}
